<style>
	.block-mb15{
		display: inline-block;margin-bottom: 15px;
	}
</style>
<div class="container-fluid" style="padding: 20px 10px 0px 10px">
	<div class="row-fluid">
		<div class="well">
		    <ul class="nav nav-tabs">
		      <li class="active"><b>录入管理</b></li>
		    </ul>
		    <div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="home">
					<form id="formid" action="/project/addPro" method="post">
						<span class="block-mb15" style="margin-left: 13px;">套餐名称：<input type="text" value="<?=$getData['project_name']?>" placeholder="套餐名称" style="width:200px;margin-left: 5px;" name="project_name" class="project_name">
						</span>
						<span class="block-mb15" style="margin-left: 13px;">购买所需积分类型：
							<select name="score_type">
								<option value="1" <?=$getData['score_type']==1?'selected':''?>>普通积分</option>
								<option value="2" <?=$getData['score_type']==2?'selected':''?>>白金积分</option>
								<option value="5" <?=$getData['score_type']==5?'selected':''?>>黄金积分</option>
								<option value="3" <?=$getData['score_type']==3?'selected':''?>>钻石积分</option>
								<option value="4" <?=$getData['score_type']==4?'selected':''?>>体验积分</option>
								<option value="6" <?=$getData['score_type']==4?'selected':''?>>口腔积分</option>
							</select>
						</span><br>
						<span class="block-mb15" style="margin-left: 14px;">套餐价格：<input type="text" value="<?=$getData['project_price']?>" placeholder="" style="width:200px;margin-left: 5px;" name="project_price" class="project_price">
						</span>
						<span class="block-mb15" style="margin-left: 68px;">套餐状态：
							<select name="project_status">
								<option value="1" <?=$getData['project_status']==1?'selected':''?>>上架</option>
								<option value="0" <?=$getData['project_status']==0?'selected':''?>>下架</option>
							</select>
						</span><br>
						<span class="block-mb15" style="margin-left: 14px;"><div id="setImd" style="display:inline;">套餐图片：<input type="text" name="cover_img" class="setImdText" style="width:388px;margin-left: 4px;" value="<?=$getData['cover_img']?>" readonly> <input type="button" class="btn btn-info setImdBtn" style='margin-top:-10px;' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['cover_img'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['cover_img'] ? transUrl($getData['cover_img']) : ''?>" style='margin-top:-8px'>查看</a></div></span>
						<!--<span class="block-mb15" style="margin-left: 13px;">套餐折扣：<input type="text" value="<?=$getData['rebate']?:'1.00'?>" placeholder="套餐折扣" style="width:200px;margin-left: 5px;" name="rebate" class="rebate">(1.00表示全额不打折)-->
						</span></br>

						<span class="block-mb15" style="margin-left: 13px;">套餐介绍：<textarea name="project_desc" style="height: 100px;width: 568px;margin-left: 75px;resize: none"><?=htmlspecialchars_decode($getData['project_desc'])?></textarea></span>

						<p style="margin-left: 15px;">选择项目：

							<?php if($cards && $getData){foreach($cards as $k=>$val){?>
							<?php if($getData['content']){foreach($getData['content'] as $key=>$v){ if($key == $val['goods_id']){?>
							<div>
								<input type="hidden" name="cards_num[]" value="<?=$key.','.$v?>">
								<div>
									<input type="text" style="margin-left: 100px;width: 400px" name="cards" value="<?=$val['goods_name']?>" disabled>

									<input type="text" value="<?=$v?>" style="width: 30px;text-align: center;" class="myClass">
                                    <input type="button" id="remove1" value="取消" style="margin-left: 6px;width: 50px;height:30px;margin-top:-8px;">
								</div>
							</div>

							<?php }}}else{?>
								<!--<div><input type="text" style="margin-left: 100px;width: 400px" name="cards" value="<?=$val['goods_name']?>" disabled> X <span><?=$v?></span></div>-->
							<?php }}}?>

                                <select name="select" id="sel" style="width: 463px;<?=$is_add==2?'margin-left: 100px':''?>">
                                    <option value="">请选择项目</option>
                                    <foreach name='acards' item='val'>
                                        <option value="<?=$val['goods_id']?>" ><?=$val['goods_name']?></option>
                                    </foreach>
                                </select>
						</p>

						<input type="hidden" value="<?=$getData['project_id']?>" name="project_id">
						<input type="hidden" value="1" name="dosubmit" />
					</form>
				</div>
				<div class="btn-toolbar">
				    <button class="btn btn-primary" id="btn-save" style="margin:18px 0 0 88px"><i class="icon-save"></i> 保存</button>
				  <div class="btn-group">
				  </div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){

	$('.setImdBtn').click(function(){
		$('#setImd').selfups();
	});

	$('#btn-save').click(function(){
		if($('input[name="project_name"]').val() == ''){
				showmsg('请输入套餐名');
				return false;
		}else if(!checkPrice($('input[name="project_price"]').val())){
				showmsg('请输入正确的价格');
				return false;
		}else if($('input[name="cover_img"]').val() == ''){
				showmsg('请选择套餐图片');
				return false;
		}else if(!$('input[name="cards_num[]"]').val()){
			showmsg('请选择项目');
			return false;
		}else{
			$('#formid').submit();
		}
	});

    function checkNum(num)
    {
        var reg = /^[0-1]{1}(.[0-9]{0,2})?$/;
        if(reg.test(num)) {
            return true;
        }
        return false ;
    }

	function checkPrice(num){
		var reg = /^\d+(\.{1}\d{1,2})?$/;
		if(reg.test(num)) {
			return true;
		}
		return false ;
	}
})
</script>

<script>
	$(function(){
//		var sel=document.getElementById("sel");
		//		sel.onchange=function(){
	//			title = $('#sel').find('option:selected').text();
	//			id = $('#sel').val();
	//			$('input[name=mycard]').remove();
	//			$('#dis').remove();
	//			if(!id){
	//				return false;
	//			}
	//			$('#sel').after('<input type="text" name="mycard" value="" style="margin-left: 10px;width: 30px" placeholder="数量"> <input type="button" id="dis" value="确定" style="margin-left: 10px;width: 50px;height:30px;margin-top:-8px;">');
	//		}
		$('#sel').change(function(){
			title = $('#sel').find('option:selected').text();
			id = $('#sel').val();
			$('input[name=mycard]').remove();
			$('#dis').remove();
			if(!id){
				return false;
			}
			$('#sel').after('<input type="text" name="mycard" value="" style="margin-left: 10px;width: 30px;text-align: center;" placeholder="数量"> <input type="button" id="dis" value="确定" style="margin-left: 10px;width: 50px;height:30px;margin-top:-8px;">');
		});

		$('#dis').live('click', function() {
			num = $('input[name=mycard]').val();
			if(!num || num<0){
				return false;
			}
			$('input[name=mycard]').remove();
			$(this).remove();
			$('#sel').before('<p><input type="text" name="cards_num[]" value="'+title+'" disabled style="width: 400px;margin-left: 100px;">  <input type="text" value="'+num+'" style="width: 30px;text-align: center"><input type="hidden" name="cards_num[]" value="'+id+','+num+'"><input type="button" id="remove" value="取消" style="margin-left: 10px;width: 50px;height:30px;margin-top:-8px;"></p>');
		});
		$('#remove').live('click', function() {
			$(this).prevAll().remove();
			$(this).remove();
		});
        $('#remove1').live('click', function() {
            $(this).parent().prev('input[type="hidden"]').remove();
            $(this).prevAll().remove();
            $(this).remove();
        });

		$('.myClass').on('keyup',function(){
            $(this).val($(this).val().replace(/[^\d]/g,''));
            var val = $(this).val();

			var old_val = $(this).parent().prev('input[type="hidden"]').val();
			var new_val = old_val.split(',')[0]+','+val;
			$(this).parent().prev('input[type="hidden"]').val(new_val);
		})

		$('input[name="mycard"],.project_price').live('keyup',function(){
			$(this).val($(this).val().replace(/[^\d]/g,''));
		})
	})
</script>